<?php
declare (strict_types = 1);

namespace app\install\controller;

use app\BaseController;
use app\install\service\install\InstallSystemService;
use app\install\service\install\observer\CreateAdminObserver;
use app\install\service\install\observer\CreateLockFileObserver;
use app\install\service\install\observer\LoadingMysqlObserver;
use app\install\service\install\observer\WriteEnvObserver;

class Index extends BaseController
{
    public function index()
    {
        return view();
    }

    public function step1()
    {
        $data = input();
        $server = new InstallSystemService($data);
        new WriteEnvObserver($server);
        $load = new LoadingMysqlObserver();
        $server->addObserver($load->checkFileExist());
        $server->handle();
        return view();
    }

    public function step2(){
        $data = input();
        $createManagerObserver = new CreateAdminObserver();
        $createLockFileObserver = new CreateLockFileObserver();
        $createManagerObserver->setData($data)->handle();
        $createLockFileObserver->handle();
        return redirect('/');
    }
}
